<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="gv-forms" layout="column">
  <h1>Groups</h1>

  <div class="gv-form">
    <h2></h2>
    <div class="gv-form-content" layout="column">
      <md-table-container ng-if="$ctrl.groups.length > 0">
        <table md-table ng-init="orderGrp = 'name'" class="gv-table-dense">
          <thead md-head md-order="orderGrp">
            <tr md-row>
              <th md-column width="30%" md-order-by="name">Name</th>
              <th md-column width="30%" style="text-align: center">Associated to new API</th>
              <th md-column width="30%" style="text-align: center">Associated to new application</th>
              <th md-column width="10%"></th>
            </tr>
          </thead>
          <tbody md-body>
            <tr md-row ng-repeat="group in $ctrl.groups | orderBy: orderGrp">
              <td md-cell>
                <a ng-click="$ctrl.selectGroupUrl(group)"> {{group.name}} </a>
                <span ng-if="group.primary_owner" flex class="badge" style="background-color: #039be5">Primary Owner</span>
              </td>
              <td md-cell style="text-align: center">
                <ng-md-icon ng-if="$ctrl.hasEvent(group, 'API_CREATE')" icon="done"></ng-md-icon>
              </td>
              <td md-cell style="text-align: center">
                <ng-md-icon ng-if="$ctrl.hasEvent(group, 'APPLICATION_CREATE')" icon="done"></ng-md-icon>
              </td>
              <td md-cell ng-click="$event.stopPropagation()" layout="row" style="padding: 10px 0">
                <span ng-if="group.manageable && !group.primary_owner">
                  <md-tooltip md-direction="top">Delete</md-tooltip>
                  <ng-md-icon
                    icon="delete"
                    ng-click="$ctrl.removeGroup($event, group.id, group.name)"
                    aria-label="delete-group"
                  ></ng-md-icon>
                </span>
              </td>
            </tr>
          </tbody>
        </table>
      </md-table-container>

      <gravitee-empty-state
        ng-if="$ctrl.groups.length == 0"
        icon="dashboard"
        model="GROUPS"
        message="There is no group to manage"
      ></gravitee-empty-state>
      <div ng-style="{'text-align': $ctrl.groups.length == 0 ? 'center' : 'none' }">
        <md-button
          permission
          permission-only="['environment-group-c']"
          ng-class="{'md-fab-bottom-right md-fab-scrollable': $ctrl.groups.length > 0, 'gv-help-displayed': $ctrl.$rootScope.helpDisplayed}"
          class="md-fab"
          aria-label="Add"
          ng-click="$ctrl.create()"
        >
          <ng-md-icon icon="add"></ng-md-icon>
        </md-button>
      </div>
    </div>
  </div>
</div>
